//
//  HMStatusOriginalView.swift
//  Weibo-swift
//
//  Created by GD on 16/9/23.
//  Copyright © 2016年 geduo. All rights reserved.
//

import UIKit
import SDWebImage
//原创
class HMStatusOriginalView: UIView {//每个View都有自己的viewModel
    
    var  statusViewModel : HMStatusViewModel?{
        didSet{//类似 MVC中的重新模型set方法
            //可以给cell 里面响应的子控件绑定数据
            screenNameLabel.text = statusViewModel?.status?.user?.screen_name
            if let userImageUrl = statusViewModel?.status?.user?.profile_image_url{
                //使用SDWebImage 加载图片
                userImageView.sd_setImage(with: URL(string:userImageUrl), placeholderImage: UIImage(named: "avatar_default_big"))
               
            }
            timeLabel.text = statusViewModel?.status?.created_at
            contentLabel.text = statusViewModel?.status?.text
            mbrankImageView.image = statusViewModel?.mbrankImage//会员逻辑处理!!!
            
            sourceLabel.text = "来自星星的你"
        }
    }
    
    private lazy var userImageView : UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))

     private lazy var verifiedImageView : UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    
    private lazy var screenNameLabel : UILabel = UILabel(textColor: UIColor.darkGray, fontSize: 14)//{
    
    private lazy var mbrankImageView : UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    
    private lazy var timeLabel : UILabel = UILabel(textColor: UIColor.darkGray, fontSize: 14)
    private lazy var sourceLabel : UILabel = UILabel(textColor: UIColor.darkGray, fontSize: 14)
    
    private lazy var contentLabel : UILabel = {
        let label = UILabel(textColor: UIColor.darkGray, fontSize: 14)
        
        label.numberOfLines = 0// 多行显示
        
        return label
    }()
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        addSubview(userImageView)
        addSubview(verifiedImageView)
        addSubview(screenNameLabel)
        addSubview(mbrankImageView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(contentLabel)
        
        //  设置约束
        userImageView.snp_makeConstraints { (make) in
            make.top.leading.equalTo(self).offset(HMHomeTableViewCellMargin)
            make.size.equalTo(CGSize(width: 35, height: 35))
        }
        
        verifiedImageView.snp_makeConstraints { (make) in
            make.centerX.equalTo(userImageView.snp_trailing)
            make.centerY.equalTo(userImageView.snp_bottom)
        }
        
        screenNameLabel.snp_makeConstraints { (make) in
            make.top.equalTo(userImageView)
            make.leading.equalTo(userImageView.snp_trailing).offset(HMHomeTableViewCellMargin)
        }
        
        mbrankImageView.snp_makeConstraints { (make) in
            make.top.equalTo(screenNameLabel)
            make.leading.equalTo(screenNameLabel.snp_trailing).offset(HMHomeTableViewCellMargin)
        }
        
        timeLabel.snp_makeConstraints { (make) in
            make.leading.equalTo(userImageView.snp_trailing).offset(HMHomeTableViewCellMargin)
            make.bottom.equalTo(userImageView)
        }
        
        sourceLabel.snp_makeConstraints { (make) in
            make.leading.equalTo(timeLabel.snp_trailing).offset(HMHomeTableViewCellMargin)
            make.bottom.equalTo(timeLabel)
        }
        
        contentLabel.snp_makeConstraints { (make) in
            make.top.equalTo(userImageView.snp_bottom).offset(HMHomeTableViewCellMargin)
            make.leading.equalTo(userImageView)
            make.width.equalTo(ScreenWidth - 2 * HMHomeTableViewCellMargin)
        }
        //关键约束-----originView的底部,距离contentLabel的底部距离为10
        self.snp_makeConstraints { (make) in
            make.bottom.equalTo(contentLabel).offset(HMHomeTableViewCellMargin)
        }
    }

}
